package com.qifan.energy.adapter;

import android.graphics.drawable.Drawable;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qifan.energy.bean.result.AddressItem;
import com.qifan.energy.R;
import com.qifan.energy.util.UIUtils;

import java.util.List;

public class AddressListAdapter extends BaseQuickAdapter<AddressItem,BaseViewHolder> {

    final static int[] defaultAddressBgs = new int[]{R.mipmap.icon_address_uncheck, R.mipmap.icon_address_checked};

    public AddressListAdapter(@Nullable List<AddressItem> data) {
        super(R.layout.address_list_item, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, AddressItem item) {
        /*checkbox选中状态*/
        TextView defaultAddressTv = helper.getView(R.id.default_address_tv);
        if (item.getDefaultStatus() == 0){
            Drawable drawable= UIUtils.getDrawable(defaultAddressBgs[0]);
            defaultAddressTv.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
            defaultAddressTv.setCompoundDrawablePadding(UIUtils.getDimensionPixelSize(R.dimen.dp_5));
            defaultAddressTv.setTextColor(UIUtils.getColor(R.color.black));
        } else {
            Drawable drawable= UIUtils.getDrawable(defaultAddressBgs[1]);
            defaultAddressTv.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
            defaultAddressTv.setCompoundDrawablePadding(UIUtils.getDimensionPixelSize(R.dimen.dp_5));
            defaultAddressTv.setTextColor(UIUtils.getColor(R.color.system_color));
        }

        //为子控件添加事件
        helper.addOnClickListener(R.id.edit_tv)
                .addOnClickListener(R.id.delete_tv)
                .addOnClickListener(R.id.default_address_tv);
        //UI赋值
        helper.setText(R.id.name_tv,item.getName())
                .setText(R.id.phone_tv,item.getPhoneNumber())
                .setText(R.id.address_detail_tv,item.getDetailAddress());
    }
}
